package mqigdcom.mqigd.core;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

import mqigdcom.mqigd.utils.LogUtils;
import mqigdcom.mqigd.utils.Utils;

/**
 * 网络状态的广播接收者
 */
public class NetworkStatusReceiver extends BroadcastReceiver {

    private static final String TAG = NetworkStatusReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        if (context != null && intent != null && ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
            if (Utils.isNetworkAvailable(context)) {
                LogUtils.d(TAG, "onReceive() isNetworkAvailable = " + true);
                // 同步本地存储的数据到服务器端
                Intent service = new Intent(context, SyncDataService.class);
                context.startService(service);
            } else {
                LogUtils.d(TAG, "onReceive() isNetworkAvailable = " + false);
            }
        }
    }
}
